var tbKeyArr = [];
var tbMap = {};//定义数据字典类型表格对象集合
var tbObjMap = {};
var dialogList = {};//定义数据字典详情页面对象集合
var dialogMap = {};//定义数据字典详情页面对象集合
var ruleMap = {};//定义规规则对象集合
var active_key = "industry";//定义当前选中的字典类型
var active_tbObj = null;
var active_dialog = null;
var tbDataUrl = "/system/dataDic/queryList";

var is_add = true;//定义是否新增变量
var seachKeys = {};
var dicStr = "";
		

/**判断是否需要重新生成HTML和JS开始**/

/**判断是否需要重新生成HTML和JS结束**/
/**初始化赋值变量开始**/

/**初始化赋值变量结束**/

$(function() {
    //初始化
    Begin();
})
/**定义检验规则类开始**/



/**定义检验规则类结束**/
var dataReturnObj = {};
var formRules = {};
	var dictionaryForm = {};
		dictionaryForm['type'] = active_key;
		var type = [];
		var type_0 = {};
		type_0['required']=true;
		type_0['trigger']='blur';
		type_0['message']='请输入类型';
		type.push(type_0);
		formRules['type']=type;
		
		dictionaryForm['code'] = '';
		var code = [];
		var code_0 = {};
		code_0['required']=true;
		code_0['trigger']='blur';
		code_0['message']='请选择代码';
		code.push(code_0);
		formRules['code']=code;
		
		dictionaryForm['codename'] = '';
		var codename = [];
		var codename_0 = {};
		codename_0['required']=true;
		codename_0['trigger']='blur';
		codename_0['message']='请选择代码中文名称';
		codename.push(codename_0);
		formRules['codename']=codename;
		
		dictionaryForm['description'] = '';
		var description = [];
		var description_0 = {};
		description_0['trigger']='blur';
		description.push(description_0);
		formRules['description']=description;
		
	dataReturnObj['dictionaryForm'] =dictionaryForm;
	dataReturnObj['rules'] = formRules;
	dataReturnObj['dialogVisible'] = true;
	dataReturnObj['disabledInput'] = false;

var dialogInfos = new Vue({
	el: "#dialogInfos",
	data: function() {
		return dataReturnObj;
	},
	methods: {
		submitForm: function(formName) {
			 this.$refs[formName].validate(function(valid){
				 if(valid)
				 {
				 	var self = this;
					var params = self['dictionaryForm'];
					var optType = "1";
					if(!is_add){
						optType = "2";
					}
					
		    		editDic(optType,params);
		    		dialogInfos.dialogVisible = false;
				 }
			 });
		},
		resetForm: function(formName) {
			this.$refs[formName].resetFields();
		}, //重置
		cancelForm: function(formName) {
			this.dialogVisible = false;
		},
		handleClose:function(){
			this.dialogVisible = false;
		}
	}
});
dialogInfos.dialogVisible = false;


/**
var vanytree = new VanyTree({
    el: "treeLeft",
    url: "/system/dataDic/queryDic",
    type: "GET",
    title: "字典分类",
    neeMove:true, //是否仅在左侧展示
    defaultProps: {
        "children": 'children',
        "label": 'tableName',
        "id": 'tableCode'
    },
    //节点点击事件
    nodeClick: function(data, node, nodeComponent) {
    	active_key = data['tableCode'];
    	for(var i=0;i<tbKeyArr.length;i++){
    		$("#"+tbKeyArr[i]+"Tb").removeClass("activeTb");
	        $("#"+tbKeyArr[i]+"Tb").addClass("displayTb");
	        $("#"+tbKeyArr[i]+"Form").removeClass("activeTb");
	        $("#"+tbKeyArr[i]+"Form").addClass("displayTb");
    	}
		$("#"+active_key+"Tb").removeClass("displayTb");
        $("#"+active_key+"Tb").addClass("activeTb");
        $("#"+active_key+"Form").removeClass("displayTb");
        $("#"+active_key+"Form").addClass("activeTb");
    	sm.getData();
    }
});
vanytree.getData();
**/
var vanytree = new Vue({
    el: "#treeLeft",
    data: function() {
        return {
            filterText: "",
            title: "",
            icon: "",
            rightIcon: "",
            contexts: "",
            justLeft: true,
            defaultExpandedKeys: [],
            data: [],
            defaultProps: {
                children: '',
                label: 'typename',
                id: 'type'
            }
        }
    },
    methods: {
        getData: function(params) {
            VanyAjax("/system/dataDic/queryDic",{},"GET").done(function(data) {
                this.defaultExpandedKeys = data.map(function(item) {
                    return item.type;
                });
                this.data = data;
            }, false, this);
        },
        isEmptyTree: function() {
            return this.data.length === 0;
        },
        filterNode: function(value, data) {
            if(!value) return true;
            return data[this.defaultProps.label].indexOf(value) !== -1;
        },
        handleNodeClick: function(data, node, nodeComponent) {
        	active_key = data['type'];
        	sm.getData();
        },
        // TODO
        resizeTree: function() {

        },
        handleCommand: function(command) {
            
        },
        rightIconClick: function() {
            
        },
        hasPre: function(nodeObj, nodeData) {
            
        },
        hasNext: function(nodeObj, nodeData) {
            
        },
        showContexts: function(isShow) {
           
        },
        renderContent:function(){
        	
        }
    },
    mounted: function() {
        /*this.$el.onmouseover = function(e) {
        	console.log(e);
        }*/
    },
    watch: {
        filterText: function(val) {
            this.$refs.tree.filter(val);
        }
    }
});
vanytree.getData();



var msg = [];
var sm = new Vue({
    el: "#tableR",
    data: function () {
        return {
            loading:false,
            keyword: '',
            tableData: [],
            total: 0,
            pageSize: 10,
            pageIndex: 1,
            tableHeight: "",
            sels: [],
            visible: true
        }
    },
    methods: {
        search: function () {
            this.getData(1, this.pageSize, this.keyword);
        },
        editDic: function (row) {
        	is_add = false;
        	dialogInfos.dialogVisible = true;
        	dialogInfos.disabledInput = true;
        	dialogInfos["dictionaryForm"]["type"]=row["type"];
        	dialogInfos["dictionaryForm"]["code"]=row["code"];
        	dialogInfos["dictionaryForm"]["codename"]=row["name"];
        	dialogInfos["dictionaryForm"]["description"]=row["description"];
        },        
        deleteDic: function(row){
        	msg = row;
        	this.$confirm('确认删除该所选字典信息？', '提示', {
        		confirmButtonText: '确定',
        		cancelButtonText: '取消',
        		type: 'warning'
        	}).then(function() {
        		var params = row;
        		editDic('3',params);
        	}).catch(function() {})
        },
        addDic: function () {
            dialogInfos.dialogVisible = true;
            dialogInfos.disabledInput = true;
            is_add = true;
            dialogInfos["dictionaryForm"]["type"]=active_key;
        	dialogInfos["dictionaryForm"]["code"]="";
        	dialogInfos["dictionaryForm"]["codename"]="";
        	dialogInfos["dictionaryForm"]["description"]="";
        },
        getData: function (pageIndex, pageSize, keyword) {
            VanyAjax(tbDataUrl, {
                pageIndex: pageIndex,
                pageSize: pageSize,
                searchValue: keyword,
                value1:active_key,
                token:sessionStorage.token
            }, "GET").done(function (data) { 
                this.currentPage = data.pageNum;
                this.pageSize = pageSize;
                this.total = data.total;
                var msgs = data.rows;
                this.tableData = msgs;
                
            }, false, this);
        },

        handleCurrentChange: function (val) {
        	this.pageIndex = val;
            this.getData(val, this.pageSize, this.keyword);
        },

        handleSelectionChange: function (selection) {
            this.sels = selection;
        },

        handleSizeChange: function(val){
        	this.pageSize = val;
            this.getData(this.pageIndex, val, this.keyword);
        }
    },
    mounted: function () {
    	var self = this;
		this.$el.style.left = "176px";
		this.tableHeight = window.innerHeight - 320;
        this.getData(this.pageIndex, this.pageSize, this.keyword);
    },
})

/**定义公共函数开始**/
/**增删改方法
 * optType[1:add;2:update;3:delete]
 * **/
function editDic(optType,params){
	var editParam = {
		optType : optType,
		code: params.code,
		name:params.codename,
		type:params.type,
		description:params.description
	};
	VanyAjax("/system/dataDic/editDic", editParam, "GET").done(function (data) { 
		sm.getData();
    }, true, this);
}


/**定义公共函数结束**/


//初始化
function Begin() {
    //面包屑
    new Vue().$mount('#crumbs');
    sessionStorage.Jurisdiction = "base_tag_addBaseRootTag,base_team_delTeamUsesr,base_user_update,base_tag_modifyBaseTag,base_team_modify,base_role_modifyRFAAndRemove,base_tagUser_export,base_customerUser_export,base_role_modifyRoleInfo,base_customer_import,base_org_delete,base_customer_addTag,base_team_delete,base_org_export,base_role_modifyRoleUser,base_user_resetUserStatus,base_org_import,base_user_export,base_tag_modifyTag,base_customer_add,base_customer_modifyTag,base_user_resetUserPassword,base_user_import,base_team_addTeamUsers,base_tag_deleteTag,base_user_deleteUsers,base_org_update,base_role_deleteRoleUser,base_user_moveUsers,base_teamUser_export,base_tag_addBaseTag,base_team_add,base_tag_selectTagUser,base_tag_addTag,base_customer_delCustomer,base_customer_addRootTag,base_tag_addRootTag,base_org_add,base_user_updateOrderNum,base_tag_deleteTagUser,base_tag_deleteBaseTag,base_customer_deleteTag,base_org_updateOrderNum,base_user_add"

}